package com.xlh.controller.conclude;

import com.xlh.common.Result;
import com.xlh.param.ValidList;
import com.xlh.param.conclude.ConcludeCourseAddParam;
import com.xlh.param.conclude.SettingCourseParam;
import com.xlh.service.conclude.ConcludeCourseService;
import com.xlh.vo.conclude.CourseListInfoVO;
import com.xlh.vo.conclude.CourseListStudentInfoVO;
import com.xlh.vo.conclude.SettingCourseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags="ConcludeCourseController", description = "工程认证 - 课程达程度", value = "课程目标路由")
@RestController
@RequestMapping("conclude/course")
public class ConcludeCourseController {


    @Autowired
    private ConcludeCourseService concludeCourseService;

    @ApiOperation("课程达成度显示列表")
    @GetMapping("/list")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<CourseListInfoVO>> list(@RequestParam("concludeId") Long concludeId) {
        List<CourseListInfoVO> list = concludeCourseService.list(concludeId);
        return Result.success(list);
    }

    @ApiOperation("课程达成度显示列表学生端")
    @GetMapping("/list/student")
    public Result<List<CourseListStudentInfoVO>> listStudent(@RequestParam("courseId") Long courseId) {
        List<CourseListStudentInfoVO> list = concludeCourseService.listStudent(courseId);
        return Result.success(list);
    }

    @ApiOperation("课程添加")
    @PostMapping("/add")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result add(@Valid @RequestBody ValidList<ConcludeCourseAddParam> concludeCourseParams){
        concludeCourseService.add(concludeCourseParams);
        return Result.success();
    }

    @ApiOperation("设置关联考核项权重值")
    @PostMapping("/settingWeight")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result settingWeight(@RequestBody @Valid SettingCourseParam settingCourseParams){

        concludeCourseService.settingWeight(settingCourseParams);
        return Result.success();
    }

    @ApiOperation("获取课程目标的权重")
    @GetMapping("/getCourseWeight")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result getCourseWeight(@RequestParam("subId") Long subId){

        SettingCourseVO courseWeight = concludeCourseService.getCourseWeight(subId);
        return Result.success(courseWeight);
    }



}
